//
//  CompostPhotosView.m
//  微博2期
//
//  Created by J on 15/12/12.
//
//

#import "CompostPhotosView.h"


@interface CompostPhotosView()
@property(nonatomic,strong)NSMutableArray* addedPhotos;

@end
@implementation CompostPhotosView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        _photos = [NSMutableArray array];
    }
    return self;

}
- (void)addPhoto:(UIImage*)photo{
    UIImageView * photoView = [[UIImageView alloc]init];
    photoView.image = photo;
    [self addSubview:photoView];
    [self.photos addObject:photo];//存储图片
    
}


- (NSMutableArray *)addedPhotos{
    
    
    if (!_addedPhotos) {
        self.addedPhotos = [NSMutableArray array];
    }
        return _addedPhotos;
}


//- (NSArray *)photos{
//
//    return self.addedPhotos;
//    
//}
//- (NSArray *)photos{
//    
//    NSMutableArray * photos = [NSMutableArray array];
//        for (UIImageView * imageView in self.subviews) {
//        [photos addObject:imageView.image];
//    }
//    
//    return photos;
//    
//}


- (void)layoutSubviews{
    [super layoutSubviews];
    //设置图片尺寸和位置
    NSUInteger count= self.subviews.count;
    NSUInteger maxCol = 4;
    CGFloat imageWH = 70;
    CGFloat imageMargin = 10;//间距
    
    for (int i=0; i<count; i++) {
        UIImageView * photoView = self.subviews[i];
        
        NSUInteger col = i%maxCol;
        photoView.x = col*(imageWH + imageMargin);
        
        NSUInteger row = i/maxCol;
        photoView.y = row*(imageWH + imageMargin);
        
        photoView.width = imageWH;
        photoView.height = imageWH;
        
    }
}


@end
